package com.sp.scmdb.action;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.sp.scmdb.bean.AddReportBean;
import com.sp.scmdb.common.action.BaseAction;
import com.sp.scmdb.entity.LabelReadingMachine;
import com.sp.scmdb.service.EmpReportService;

@Controller("addReportAction")
@Scope("prototype")
public class AddReportAction extends BaseAction<AddReportBean> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static Log log = LogFactory.getLog(AddReportAction.class);
	private EmpReportService empReportService;

	@Autowired
	public void setEmpReportService(EmpReportService empReportService) {
		this.empReportService = empReportService;
	}

	public String reportManager() {
		try {
			String message = request.getParameter("message");
			if(message!=null){
				request.setAttribute("message",message);
			}
			List<LabelReadingMachine> ruList = empReportService.readerList();
			request.setAttribute("readerList", ruList);
			return "reportManager";
		} catch (Exception e) {
			e.printStackTrace();
			log.error("reportManager is fail! reason:" + e.getMessage());
			return "fail";
		}
	}

	public String addReport(){
		try{
			String message = empReportService.addReport(entity);
			request.setAttribute("message", message);
			return "addReport";
		}
		catch(Exception e){
			e.printStackTrace();
			log.error("reportManager is fail! reason:" + e.getMessage());
			return "fail";
		}
	}
}
